import Scene from "../Scene";
import { DirectionCode, KeyEventParameters, SceneState, SceneUtils, TButton, TLayout } from "../SceneControl";
import UIMrg from "../../Script/UIMrg";
import GuidePanel from "../../Script/GuidePanel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GuideMskNodeScene extends Scene {
    line: cc.Node;

    protected onEnable(): void {
        super.onEnable();
        let contentPanel = UIMrg.UIMrg.getPanel(GuidePanel.GuidePanel);
        this.line = this.node.getChildByName("line");

        let shou1 = cc.find("hand/shouji", this.node);
        this.line.on("active-in-hierarchy-changed", () => {
            shou1.active = !this.line.active
        }, this)

        this.initScene();
    }

    protected onDisable(): void {
        super.onDisable();
        this.line.targetOff(this);
    }

    public initScene() {
        let layout = new TLayout();
        let btn = new TButton(this.node);
        let hot = cc.find("hot", this.node);

        btn.addKeyDownEvent((para: KeyEventParameters) => {
            if (para.DirectionCode == DirectionCode.ENTER) {
                if (hot.active) {
                    SceneUtils.emitButton(hot);
                }
                let contentPanel = UIMrg.UIMrg.getPanel(GuidePanel.GuidePanel);
                contentPanel && contentPanel._target && SceneUtils.emitButton(contentPanel._target);
            }
        })
        layout.buttonList = [
            [btn]
        ]

        this.tscene.onBack = () => {
            let contentPanel = UIMrg.UIMrg.getPanel(GuidePanel.GuidePanel);
            if (contentPanel && contentPanel._target && contentPanel._target.name == "btnClose") {
                SceneUtils.emitButton(contentPanel._target);
            }

        }
        this.tscene.sceneState = SceneState.hideFinger;
        this.tscene.addLayout(layout);
        this.tscene.joinController();
    }

}
